package com.hf.eagle.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hf.eagle.dao.OrderDealInfoDao;
import com.hf.eagle.dao.OrderInfoDao;
import com.hf.eagle.dao.OrderProductDetailDao;
import com.hf.eagle.domain.OrderDealInfo;
import com.hf.eagle.domain.OrderInfo;
import com.hf.eagle.domain.OrderProductDetail;
import com.hf.eagle.service.OrderInfoService;

/**
 * @author Xu,XiaoYuan
 * @version 2011-11-13 19:34
 */
@Service
public class OrderInfoServiceImpl implements OrderInfoService {

	@Resource
	private OrderInfoDao orderInfoDao;

	@Resource
	private OrderDealInfoDao orderDealInfoDao;

	@Resource
	private OrderProductDetailDao orderProductDetailDao;

	public Long createOrderInfo(OrderInfo t) {
		Long order_id = this.orderInfoDao.insertEntity(t);

		List<OrderProductDetail> list = t.getProductDetailList();
		if (null != list && list.size() > 0) {
			for (OrderProductDetail orderProductDetail : list) {
				orderProductDetail.setOrder_id(order_id);
				orderProductDetailDao.insertEntity(orderProductDetail);
			}
		}
		return order_id;
	}

	public OrderInfo getOrderInfo(OrderInfo t) {
		return this.orderInfoDao.selectEntity(t);
	}

	public Long getOrderInfoCount(OrderInfo t) {
		return this.orderInfoDao.selectEntityCount(t);
	}

	public List<OrderInfo> getOrderInfoList(OrderInfo t) {
		return this.orderInfoDao.selectEntityList(t);
	}

	public int modifyOrderInfo(OrderInfo t) {
		if (null != t.getMap().get("archive") && null != t.getMap().get("orderDealInfo")) {
			OrderDealInfo orderDealInfo = (OrderDealInfo) t.getMap().get("orderDealInfo");
			orderDealInfoDao.insertEntity(orderDealInfo);
		}

		return this.orderInfoDao.updateEntity(t);
	}

	public int removeOrderInfo(OrderInfo t) {
		return this.orderInfoDao.deleteEntity(t);
	}

	public List<OrderInfo> getOrderInfoPaginatedList(OrderInfo t) {
		return this.orderInfoDao.selectEntityPaginatedList(t);
	}

}
